home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Morphos / GCC / ppc-amigaos / include / dll.h < prev    next >
C/C++ Source or Header  |  2000-02-14  |  5KB  |  213 lines

  1. #ifndef __DLL_H
  2. #define __DLL_H
  3.  
  4. #ifdef __DLL_LIB_BUILD
  5. #include <exec/exec.h>
  6. #endif
  7.  
  8. /************************************************************
  9.  * External structures
  10.  ************************************************************/
  11.  
  12. typedef struct dll_sExportSymbol
  13. {
  14.     void *      SymbolAddress;
  15.     char *      SymbolName;
  16. } dll_tExportSymbol;
  17.  
  18. typedef struct dll_sImportSymbol
  19. {
  20.     void **     SymbolPointer;
  21.     char *      SymbolName;
  22.     char *      DLLFileName;
  23.     char *      DLLPortName;
  24. } dll_tImportSymbol;
  25.  
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29.  
  30. int     dllImportSymbols(void);
  31. void *  dllLoadLibrary(char *name,char *portname);
  32. void    dllFreeLibrary(void *hinst);
  33. void *  dllGetProcAddress(void *hinst,char *name);
  34. int     dllKillLibrary(char *portname);
  35.  
  36. int     DLL_Init(void);
  37. void    DLL_DeInit(void);
  38.  
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42.  
  43.  
  44. /*
  45.  * Prototypes for DLL implementations
  46.  */
  47.  
  48. extern dll_tExportSymbol DLL_ExportSymbols[];
  49. extern dll_tImportSymbol DLL_ImportSymbols[];
  50.  
  51. /************************************************************
  52.  * Internal structures
  53.  ************************************************************/
  54.  
  55. void *dllInternalLoadLibrary(char *filename,char *portname,int raiseusecount);
  56.  
  57. /*
  58. ** Typedefs for function vectors.
  59. ** Any DLL implementor must deliver these functions.
  60. */
  61. typedef void* (*dll_tFindResourceFn)(int, char*);
  62. typedef void* (*dll_tLoadResourceFn)(void*);
  63. typedef void  (*dll_tFreeResourceFn)(void*);
  64.  
  65. /*
  66. ** The stack type the application using the DLL prefers.
  67. ** If there is no support for this type in your DLL, return
  68. ** DLLERR_StackNotSupported.
  69. **
  70. ** Implementation note: In the startup code, return different
  71. ** function pointers depending on the stack frame. This is
  72. ** the preferred method. Some of the stack frames might be
  73. ** identical, for example, since there is not UBYTE passing
  74. ** on the stack for the different DLL interface functions,
  75. ** using the same stack from for all 68k stack types is safe.
  76. */
  77.  
  78. typedef enum
  79. {
  80.     DLLSTACK_STORM         = 0x01,    // 68k, StormC
  81.     DLLSTACK_EGCS          = 0x02,    // 68k, GCC or egcs
  82.     DLLSTACK_SAS           = 0x04,    // 68k, SAS/C
  83.     DLLSTACK_VBCC          = 0x08,    // 68k, vbcc
  84.     DLLSTACK_POWEROPEN     = 0x10,    // PPC, StormC or vbcc
  85.     DLLSTACK_SYSV          = 0x20     // PPC, egcs
  86.     //..
  87. } dll_tStackType;
  88.  
  89. #ifdef __STORM__
  90. #ifdef __PPC__
  91. #define DLLSTACK_DEFAULT DLLSTACK_POWEROPEN
  92. #else
  93. #define DLLSTACK_DEFAULT DLLSTACK_STORM
  94. #endif
  95. #else //not Storm
  96. #ifdef __VBCC__
  97. #ifdef __PPC__
  98. #define DLLSTACK_DEFAULT DLLSTACK_POWEROPEN
  99. #else
  100. #define DLLSTACK_DEFAULT DLLSTACK_VBCC
  101. #endif
  102. #else //not VBCC
  103. #ifdef __GNUC__
  104. #ifdef __PPC
  105. #define DLLSTACK_DEFAULT DLLSTACK_SYSV
  106. #else
  107. #define DLLSTACK_DEFAULT DLLSTACK_EGCS
  108. #endif
  109. #else //not GCC
  110. #ifdef __SASC__
  111. #define DLLSTACK_DEFAULT DLLSTACK_SAS
  112. #endif
  113. #endif //GCC
  114. #endif //VBCC
  115. #endif //STORMC
  116.  
  117. #ifdef __DLL_LIB_BUILD
  118.  
  119. typedef enum
  120. {
  121.     DLLERR_NoError              = 0,    // No error occured
  122.     DLLERR_StackNotSupported    = 1,    // Illegal stack frame
  123.     DLLERR_OutOfMemory          = 2     // Init failed due to memory shortage
  124. } dll_tErrorCode;
  125.  
  126.  
  127. typedef enum
  128. {
  129.     DLLMTYPE_Open       = 0,
  130.     DLLMTYPE_Close      = 1,
  131.     DLLMTYPE_SymbolQuery    = 2,
  132.     DLLMTYPE_Kill       = 3
  133. } dll_tMessageType;
  134.  
  135. typedef struct dll_sSymbolQuery
  136. {
  137.     // Preferred stack type of the main program
  138.     dll_tStackType  StackType;
  139.         
  140.     // Name of the Symbol
  141.     char *      SymbolName;
  142.  
  143.     // Where to put the Symbol Address
  144.     void **     SymbolPointer;
  145. } dll_tSymbolQuery;
  146.  
  147. /*
  148. */
  149. typedef struct dll_sMessage
  150. {
  151.     // Message for sending
  152.     struct Message          Message;
  153.  
  154.     dll_tMessageType    dllMessageType;
  155.  
  156.     union 
  157.     {
  158.         struct
  159.         {
  160.     // Preferred stack type of the main program
  161.             dll_tStackType  StackType;
  162.  
  163.     // Initialization error code
  164.             dll_tErrorCode  ErrorCode;
  165.         } dllOpen;
  166.  
  167.         struct
  168.         {
  169.             //Empty for now
  170.         } dllClose;
  171.  
  172.         dll_tSymbolQuery    dllSymbolQuery;
  173.  
  174.     } dllMessageData;
  175.  
  176.     // ... Might grow
  177. } dll_tMessage;
  178.  
  179. /*
  180. ** This structure is returned by the LoadLibrary() call. It is strictly
  181. ** Off-Limits for both the caller and the DLL but rather used internally
  182. ** to for tracking resources and other stuff for the DLL. This structure
  183. ** may change at any time.
  184. */
  185. struct dll_sInstance
  186. {
  187.     struct MsgPort      *dllPort;
  188.     dll_tStackType      StackType;
  189.     dll_tFindResourceFn FindResource;
  190.     dll_tLoadResourceFn  LoadResource;
  191.     dll_tFreeResourceFn FreeResource;
  192.     // ... Might grow
  193. };
  194.  
  195. /************************************************************
  196.  * Misc
  197.  ************************************************************/
  198.  
  199.  
  200. #endif // DLL_LIB_BUILD
  201.  
  202. #ifndef HINSTANCE
  203. typedef void * HINSTANCE;
  204. #endif
  205.  
  206. #ifdef __GNUC__
  207. #ifdef __PPC
  208. #define __saveds
  209. #endif
  210. #endif
  211.  
  212. #endif
  213.